package cn.jtfadmin.base.lang.common.utils;

import cn.afterturn.easypoi.excel.ExcelImportUtil;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecuterUtils {

    private static  ExecutorService executorService ;


    public  static <T> T exec(Callable<T> callable) {
        try {
            return getExecutorService().submit(callable).get();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 获取线程池服务
     * @return
     */
    public static ExecutorService getExecutorService(){
        if(executorService == null){
            synchronized (ExcelImportUtil.class){
                if(executorService == null){
                    executorService =  Executors.newCachedThreadPool();
                }
            }
        }
        return executorService;
    }
}
